package com.woniu.cq.medical.service.impl;

import com.woniu.cq.medical.common.PageResult;
import com.woniu.cq.medical.entity.AdministrativeWorkloadAccount;
import com.woniu.cq.medical.dao.AdministrativeWorkloadAccountMapper;
import com.woniu.cq.medical.service.AdministrativeWorkloadAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-09
 */
@Service
public class AdministrativeWorkloadAccountServiceImpl extends ServiceImpl<AdministrativeWorkloadAccountMapper, AdministrativeWorkloadAccount> implements AdministrativeWorkloadAccountService {
    @Autowired
    private AdministrativeWorkloadAccountMapper administrativeWorkloadAccountMapper;
    @Override
    public List<AdministrativeWorkloadAccount> getRealTimeData() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String dateTime = format.format(new Date());
        List<AdministrativeWorkloadAccount> list=null;
        try {
            Date date=format.parse(dateTime);
            list=administrativeWorkloadAccountMapper.getRealTimeData(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public PageResult pageQuery(int pageIndex, int pageSize, String administrativeName, Date attendanceDateBefore, Date attendanceDateAfter) {
        long totalCount=administrativeWorkloadAccountMapper.totalCount(administrativeName,attendanceDateBefore, attendanceDateAfter);
        int pageStart=(pageIndex-1)*pageSize;
        List<AdministrativeWorkloadAccount> list=administrativeWorkloadAccountMapper.pageQuery(pageStart,pageSize,administrativeName,attendanceDateBefore, attendanceDateAfter);
        System.out.println(list);
        return PageResult.success(totalCount,pageIndex,pageSize,list);
    }
}
